<?php
header("Content-type:text/html; charset=utf-8");

// 制定允许其他域名访问
header("Access-Control-Allow-Origin:*");
// 响应类型
header('Access-Control-Allow-Methods:POST');
// 响应头设置
header('Access-Control-Allow-Headers:x-requested-with, content-type');
include 'config.php';
$name=$_POST['username'];
$pwd=$_POST['password'];//获取表单提交的内容用两个变量来存post方式接受的值
$usernameflag=$_POST['usernameflag'];

// $name = 'root';

$sql="select flag,timedata from t_admin where user='$name'";//查询语句
$query=mysqli_query($conn,$sql);

$reslist = array();
$i=0;
while ($row=mysqli_fetch_row($query)){
  $reslist[$i] = $row;
  $i++;
}

date_default_timezone_set("PRC");//设置时区

$today = date("Y-m-d h:i:s H ");
if($reslist[0][0] == 7){
	$flagday = date("Y-m-d h:i:s",strtotime(date("Y-m-d h:i:s")." +10 minutes"));
	$sql="UPDATE `t_admin` SET `timedata` = '$flagday' WHERE `t_admin`.`user` = '$name'";
	$query=mysqli_query($conn,$sql);
	$sql="UPDATE `t_admin` SET `flag` = '5' WHERE `t_admin`.`user` = '$name'";
	$query=mysqli_query($conn,$sql);
}
if($reslist[0][1] > $today){
	echo json_encode(['false']);
}
else{
	$sql="select * from t_admin where user='$name' and pwd='$pwd'";//查询语句
	$query=mysqli_query($conn,$sql);//函数执行一条 MySQL 查询。
	@$arr=mysqli_fetch_array($query);//然后从$query中取一行数字数组

	if(is_array($arr)){//对$arr进行判断
	    setcookie('username',$name,time()+3600);//设置cookie,时间为一小时，（以秒为单位）
	    $json = [1,$name,$pwd];
	    echo json_encode($json);
	}else{
		$sql="UPDATE `t_admin` SET `flag` = '$usernameflag' WHERE `t_admin`.`user` = '$name'";
		$query=mysqli_query($conn,$sql);
		echo json_encode([$usernameflag]);
	}

}


$conn->close();   


?>